package leetcode;

import java.util.Arrays;

/**
 * @Project: algorithm-learning-java
 * @Package: leetcode
 * @Author: Ruoyu Wang
 * @User: ruoyu.wang@momenta.ai
 * @DateTime: 2024/1/4 16:11
 */
public class Q0034 {
    public int[] searchRange(int[] nums, int target) {
        if (nums.length == 0) return new int[]{-1, -1};

        int l = 0, r = nums.length - 1;
        while (l < r) {
            int mid = l + r >> 1;
            if (nums[mid] >= target) r = mid;
            else l = mid + 1;
        }

        if (nums[l] != target) return new int[]{-1, -1};

        int tmp = l;
        l = 0;
        r = nums.length - 1;
        while (l < r) {
            int mid = l + r + 1 >> 1;
            if (nums[mid] <= target) l = mid;
            else r = mid - 1;
        }

        return new int[]{tmp, r};
    }

    public static void main(String[] args) {
        Q0034 sl = new Q0034();
        int[] nums = {5, 7, 7, 8, 8, 10};
        System.out.println(Arrays.toString(sl.searchRange(nums, 8)));
    }
}